home *** CD-ROM | disk | FTP | other *** search
- unit WinSvcX;
-
- interface
-
- {===============================================================================}
- { This unit is simply for use with the NT Service demonstration supplied with }
- { the Delphi magazine. }
- { It contains only those definitions required to support the article. The source}
- { for the defintions are Winnt.H and WinSVC.Pas (from the Delphi3 version). }
- {===============================================================================}
-
- uses Windows;
-
- { >>>>>>>> Start of definitions originating in WinNT.H }
-
- const
-
- { Event types}
-
- EVENTLOG_SUCCESS = $0000;
- EVENTLOG_ERROR_TYPE = $0001;
- EVENTLOG_WARNING_TYPE = $0002;
- EVENTLOG_INFORMATION_TYPE = $0004;
- EVENTLOG_AUDIT_SUCCESS = $0008;
- EVENTLOG_AUDIT_FAILURE = $0010;
-
- { Service types }
-
- SERVICE_WIN32_OWN_PROCESS = $00000010;
- SERVICE_WIN32_SHARE_PROCESS = $00000020;
- SERVICE_INTERACTIVE_PROCESS = $00000100;
-
- { Service start types }
-
- SERVICE_BOOT_START = $00000000;
- SERVICE_SYSTEM_START = $00000001;
- SERVICE_AUTO_START = $00000002;
- SERVICE_DEMAND_START = $00000003;
- SERVICE_DISABLED = $00000004;
-
- { Service start error options }
-
- SERVICE_ERROR_IGNORE = $00000000;
- SERVICE_ERROR_NORMAL = $00000001;
- SERVICE_ERROR_SEVERE = $00000002;
- SERVICE_ERROR_CRITICAL = $00000003;
-
- SECURITY_DESCRIPTOR_REVISION = 1;
-
- { >>>>>>>> End of definitions originating in WinNT.H }
-
- { The following come from WinSVC.Pas }
-
- // Service control requests }
-
- SERVICE_CONTROL_STOP = $00000001;
- SERVICE_CONTROL_PAUSE = $00000002;
- SERVICE_CONTROL_CONTINUE = $00000003;
- SERVICE_CONTROL_INTERROGATE = $00000004;
- SERVICE_CONTROL_SHUTDOWN = $00000005;
-
- // Service State -- for CurrentState
-
- SERVICE_STOPPED = $00000001;
- SERVICE_START_PENDING = $00000002;
- SERVICE_STOP_PENDING = $00000003;
- SERVICE_RUNNING = $00000004;
- SERVICE_CONTINUE_PENDING = $00000005;
- SERVICE_PAUSE_PENDING = $00000006;
- SERVICE_PAUSED = $00000007;
-
- // Controls Accepted (Bit Mask)
-
- SERVICE_ACCEPT_STOP = $00000001;
- SERVICE_ACCEPT_PAUSE_CONTINUE = $00000002;
- SERVICE_ACCEPT_SHUTDOWN = $00000004;
-
- // Handle Types
-
- type
- SC_HANDLE = THandle;
- SERVICE_STATUS_HANDLE = DWORD;
-
- // Service Status Structure
-
- type
- PServiceStatus = ^TServiceStatus;
- TServiceStatus = record
- dwServiceType: DWORD;
- dwCurrentState: DWORD;
- dwControlsAccepted: DWORD;
- dwWin32ExitCode: DWORD;
- dwServiceSpecificExitCode: DWORD;
- dwCheckPoint: DWORD;
- dwWaitHint: DWORD;
- end;
-
- // Prototype for the Service Main Function
-
- type
- TServiceMainFunction = TFarProc;
-
- // Prototype for the Service Control Handler Function
-
- type
- THandlerFunction = TFarProc;
-
- //
- // Service Start Table
- //
- type
- PServiceTableEntry = ^TServiceTableEntry;
- TServiceTableEntry = record
- lpServiceName: PAnsiChar;
- lpServiceProc: TServiceMainFunction;
- end;
-
- // Service Control Manager object specific access types
-
- const
- SC_MANAGER_CONNECT = $0001;
- SC_MANAGER_CREATE_SERVICE = $0002;
- SC_MANAGER_ENUMERATE_SERVICE = $0004;
- SC_MANAGER_LOCK = $0008;
- SC_MANAGER_QUERY_LOCK_STATUS = $0010;
- SC_MANAGER_MODIFY_BOOT_CONFIG = $0020;
-
- SC_MANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or
- SC_MANAGER_CONNECT or
- SC_MANAGER_CREATE_SERVICE or
- SC_MANAGER_ENUMERATE_SERVICE or
- SC_MANAGER_LOCK or
- SC_MANAGER_QUERY_LOCK_STATUS or
- SC_MANAGER_MODIFY_BOOT_CONFIG);
-
- // Service object specific access type
-
- SERVICE_QUERY_CONFIG = $0001;
- SERVICE_CHANGE_CONFIG = $0002;
- SERVICE_QUERY_STATUS = $0004;
- SERVICE_ENUMERATE_DEPENDENTS = $0008;
- SERVICE_START = $0010;
- SERVICE_STOP = $0020;
- SERVICE_PAUSE_CONTINUE = $0040;
- SERVICE_INTERROGATE = $0080;
- SERVICE_USER_DEFINED_CONTROL = $0100;
-
- SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or
- SERVICE_QUERY_CONFIG or
- SERVICE_CHANGE_CONFIG or
- SERVICE_QUERY_STATUS or
- SERVICE_ENUMERATE_DEPENDENTS or
- SERVICE_START or
- SERVICE_STOP or
- SERVICE_PAUSE_CONTINUE or
- SERVICE_INTERROGATE or
- SERVICE_USER_DEFINED_CONTROL);
-
- function CloseServiceHandle(hSCObject: SC_HANDLE): BOOL; stdcall;
- function CreateService(hSCManager: SC_HANDLE; lpServiceName, lpDisplayName: PChar;
- dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl: DWORD;
- lpBinaryPathName, lpLoadOrderGroup: PChar; lpdwTagId: LPDWORD; lpDependencies,
- lpServiceStartName, lpPassword: PChar): SC_HANDLE; stdcall;
- function DeleteService(hService: SC_HANDLE): BOOL; stdcall;
- function OpenSCManager(lpMachineName, lpDatabaseName: PChar;
- dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
- function OpenService(hSCManager: SC_HANDLE; lpServiceName: PChar;
- dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
- function RegisterServiceCtrlHandler(lpServiceName: PChar;
- lpHandlerProc: ThandlerFunction): SERVICE_STATUS_HANDLE; stdcall;
- function SetServiceStatus(hServiceStatus: SERVICE_STATUS_HANDLE;
- var lpServiceStatus: TServiceStatus): BOOL; stdcall;
- function StartServiceCtrlDispatcher(
- var lpServiceStartTable: TServiceTableEntry): BOOL; stdcall;
-
- implementation
-
- const
- ADVAPI32 = 'ADVAPI32.dll';
-
- function CloseServiceHandle; external ADVAPI32 name 'CloseServiceHandle';
- function CreateService; external ADVAPI32 name 'CreateServiceA';
- function DeleteService; external ADVAPI32 name 'DeleteService';
- function OpenSCManager; external ADVAPI32 name 'OpenSCManagerA';
- function OpenService; external ADVAPI32 name 'OpenServiceA';
- function RegisterServiceCtrlHandler;external ADVAPI32 name 'RegisterServiceCtrlHandlerA';
- function SetServiceStatus; external ADVAPI32 name 'SetServiceStatus';
- function StartServiceCtrlDispatcher; external ADVAPI32 name 'StartServiceCtrlDispatcherA';
-
- end.
-